package com.lostsheep.rpc.impl.user;

import com.lostsheep.dto.CommonDTO;
import com.lostsheep.dto.UserDTO;
import com.lostsheep.rpc.UserRpc;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * <b><code>UserRpcImpl</code></b>
 * <p/>
 * Description
 * <p/>
 * <b>Creation Time:</b> 2024/7/6.
 *
 * @author dengzhen
 * @since spring-cloud-dubbo
 */
@DubboService
public class UserRpcImpl implements UserRpc {
    
    @Override
    public CommonDTO<List<UserDTO>> getUsers() {
        UserDTO userDTO = UserDTO.builder()
                .id(1L)
                .userName("张三")
                .address("广东省广州市天河区")
                .age(18)
                .build();
        List<UserDTO> list = new ArrayList<>();
        list.add(userDTO);
        return CommonDTO.success("请求成功!", list);
    }

    @Override
    public UserDTO getUser(Long id) {
        if (!Objects.equals(id, 1L)) return new UserDTO();
        
        return UserDTO.builder()
                .id(1L)
                .userName("张三")
                .address("广东省广州市天河区")
                .age(18)
                .phone(null)
                .build();
    }
}
